<?php
/*
 * @ https://EasyToYou.eu - IonCube v11 Decoder Online
 * @ PHP 7.2 & 7.3
 * @ Decoder version: 1.1.6
 * @ Release: 10/08/2022
 */

// Decoded file for php version 71.
class Cret
{
    private $uniacid;
    private $goods_name;
    private $base_url;
    private $get_auth_url;
    private $http_host;
    private $server_name;
    private $request_time;
    private $public_key;
    private $domain_name_info;
    private $is_debug = false;
    private $token_path;
    public function __construct()
    {
    }
    public function returnDataInfo($data = [], $msg = "", $code = 20000)
    {
        $resultData = ["code" => $code, "msg" => $msg, "data" => $data];
        return $resultData;
    }
    public function returnErrorDataInfo($msg = "", $code = -1, $data = [])
    {
        return $this->returnDataInfo($data, $msg, $code);
    }
    private function getPostData($siginStr)
    {
        $postData = $this->getPublicPostData();
        $postData["sigin"] = $siginStr;
        return $postData;
    }
    private function getSiginData($extData = [], $siginType = 1)
    {
        $data = $this->getPublicPostData();
        if(!empty($extData)) {
            $data["ext_data"] = $extData;
        }
        ksort($data);
        $str_data = json_encode($data);
        if($siginType == 1) {
            @openssl_public_encrypt($str_data, $encrypted, $this->public_key);
            if(empty($encrypted)) {
                return false;
            }
            $encrypted = base64_encode($encrypted);
        } else {
            $encrypted = $this->getSiginDataByHash($data);
        }
        return $encrypted;
    }
    private function getSiginDataByHash($data)
    {
        $data["token"] = $data["token"] ? $data["token"] : "";
        $this->log("getSiginDataByHash data ", $data);
        $data = is_array($data) ? json_encode($data) : (is_string($data) ? $data : time() . "") . "LongbingShuixian";
        $siginStr = hash("sha256", $data);
        return $siginStr;
    }
    private function getPublicPostData()
    {
        $app_model_name = config("app.AdminModelList")["app_model_name"];
        $token = @file_get_contents($this->token_path);
        $token = $token ? json_decode($token, true) : "";
        if(!empty($token)) {
            $token = $token["token"];
        }
        $data = ["uniacid" => $this->uniacid, "app_model_name" => $app_model_name, "goods_name" => $this->goods_name, "http_host" => $this->http_host, "server_name" => $this->server_name, "request_time" => $this->request_time, "token" => $token];
        return $data;
    }
    private function getPublicKey()
    {
        if(!empty($this->public_key)) {
            return $this->public_key;
        }
        $siginStr = $this->getSiginData([], 2);
        $result = $this->curl_post($this->get_auth_url, $this->getPostData($siginStr));
        $result = json_decode($result, true);
        $this->domain_name_info = $result["data"]["domain_name_info"];
        $token = $result["data"]["token"];
        $this->public_key = $result["data"]["public_key"];
        return $this->public_key;
    }
    private function curl_post($url, $data = [])
    {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
        $output = curl_exec($ch);
        curl_close($ch);
        return $output;
    }
}

?>